package cn.lb.permission.service.impl;


import cn.lb.permission.domain.Permission;
import cn.lb.permission.mapper.PermissionMapper;
import cn.lb.permission.query.PermissionQuery;
import cn.lb.permission.service.IPermissionService;
import cn.lb.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements IPermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public PageList<Permission> listPage(PermissionQuery query) {
        // 1 根据query查询总条数
        long total = permissionMapper.loadTotal(query);

        // 2 如果总条数>0,就根据query查询当前页数据
        if(total > 0){
            List<Permission> rows = permissionMapper.loadData(query);
            return new PageList<Permission>(rows,total);
        }
        return new PageList<>();
    }

    @Override
    public List<Permission> tree() {


        return permissionMapper.selectpermissions();
    }

    @Override
    public List<String> getsns(Long employeeId) {

        return permissionMapper.selectsns(employeeId);
    }
}
